package Demo01.Exception;
//throw  抛出指定异常

public class Demo02Throw {
    public static void main(String[] args) {
        int[] arr = new int[3];
        int e = getElement(arr, 3);
        System.out.println(e);
    }

    public static int getElement(int[] arr,int index){
        if(arr == null){
            throw new NullPointerException("传递的数组值是null");
        }
        if(index <0 || index > arr.length - 1){
            throw new ArrayIndexOutOfBoundsException("传递的索引超出了数组的取值范围");
        }
        int ele = arr[index];
        return ele;
    }
}
